<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="gdufs.stat.service.FwtjQuery" %>
<%@page import="java.util.*" %>
<%@page import="java.sql.Date" %>
<%@page import="java.text.*" %>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="org.apache.commons.lang.StringUtils" %>
<html>
<head>
<%@include file="/inc/head.jsp" %>
<%
ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(application); 
FwtjQuery fwtjQuery = (FwtjQuery)context.getBean("fwtjQuery");
%>
<%

	String starttime = request.getParameter("starttime");
	String endtime = request.getParameter("endtime");
	String metier = request.getParameter("metier");
	String userid = request.getParameter("userid");
	String username = request.getParameter("username");
	String deptname = request.getParameter("deptname");
	String method = request.getParameter("method");

	List<Map> queryList = new ArrayList<Map>();
	if(!StringUtils.isEmpty(method)){
		queryList = fwtjQuery.queryVisitList(metier,starttime,endtime,userid,username,deptname);
	}
	if(metier == null){
		metier = "0";
	}
	
	deptname = StringUtils.trimToEmpty(deptname);
	starttime = StringUtils.trimToEmpty(starttime);
	endtime = StringUtils.trimToEmpty(endtime);
	username = StringUtils.trimToEmpty(username);
	userid = StringUtils.trimToEmpty(userid);
	
	
%>

<title>查询登录情况</title>
<script type="text/javascript" src="../FusionCharts/FusionCharts.js"></script>
<link href="../css/calendar.css" rel="stylesheet" type="text/css">
<script language=javascript src="../javascripts/calendar/calendar.js"></script>
<script language=javascript src="../javascripts/calendar/calendar-zh.js"></script>
<script language=javascript src="../javascripts/calendar/calendar-setup.js"></script>
<script type="text/javascript">
	function doSubmit(){
		var starttime = document.getElementById("starttime").value;
		var endtime = document.getElementById("endtime").value;
		var userid = document.getElementById("userid").value;
		var username = document.getElementById("username").value;
		var deptname = document.getElementById("deptname").value;

		if((starttime == null || starttime == "") && (endtime == null || endtime == "") && (userid == null || userid == "") && (username == null || username == "") && (deptname == null || deptname == "") ){
			alert("请输入参数进行查询");
			return false;
		}else{
			document.forms[0].submit();
		}
	}

	function initSelect(){
		var metier = document.getElementById("metier");
		var value = "<%=metier%>";
		for(var i = 0 ; i < metier.options.length ; i++){
			var option = metier.options[i];
			if(option.value == value ){
				option.selected="selected";
				return;
			}
		}
	}

	function doReset(){
		document.getElementById("metier").selectedIndex = 0;
		document.getElementById("starttime").value = "";
		document.getElementById("endtime").value = "";
		document.getElementById("userid").value = "";
		document.getElementById("username").value = "";
		document.getElementById("deptname").value = "";
	}
</script>
</head>
<body onload="initSelect();" style="margin: 5px;">
<!-- 查询框 -->
	<form action="staticsQuery.jsp" method="post">
		<input type="hidden" id="method" name="method" value="query">
		<div style="width: 100%;">
		<table width="100%" border="1" cellpadding="0" cellspacing="0" style="padding:5px;border:1px solid #aaaaaa;background-color: #efefef;border-collapse:collapse;" bordercolor="#ffffff">
				<tr>
					<td align="right">部门名称:</td>
					<td><input type="text" id="deptname" name="deptname" value="<%=deptname %>" ></td>
					<td align="right">用户id:</td>
					<td><input type="text" id="userid" name="userid" value="<%=userid %>" > </td>
					<td align="right">用户名称:</td>
					<td><input type="text" id="username" name="username" value="<%=username %>" ></td>
				</tr>
				<tr>
					<td align="right">用户类别:</td>
					<td><select id="metier" name="metier" style="background-color: white;">
						<option value="0" >所有用户</option>
						<option value="1">教师</option>
						<option value="2">研究生</option>
						<option value="3">本科生</option>
					</select></td>
					<td align="right">开始时间:</td>
					<td><input type="text" id="starttime" name="starttime" value="<%=starttime %>"
						style="background-color: white;">&nbsp;<input name="" type="image" src="../images/iconDate.gif" id="_starttime"></td>
					<td align="right">结束时间:</td>
					<td><input type="text" id="endtime" name="endtime" value="<%=endtime %>"
						style="background-color: white;">&nbsp;<input name="" type="image" src="../images/iconDate.gif" id="_endtime"></td>
				</tr>
				<tr>
					<td colspan="6" align="center" style="background-color: #ffffff"><input type="button" value="提交" onclick="doSubmit();" />&nbsp;<input type="button" onclick="doReset();"
						value="重置"></td>
				</tr>
			</table>
		</div>
	
	<!-- 列表统计 -->
		<div style="width: 100%;">
		<table cellpadding="3" cellspacing="0" width="100%" border="1" style="border:1px solid #aaaaaa;border-collapse: collapse;margin-top: 5px;" bordercolor="#aaaaaa">
				<tr >
					<th width="20%">部门</th>
					<th width="8%">类别</th>
					<th width="8%">用户</th>
					<th width="12%">主机</th>
					<th width="20%">登录ip</th>
					<th width="16%">登录时间</th>
					<th width="16%">登出时间</th>
				</tr>
				<%
				if(queryList != null && queryList.size() == 0){
				%>
				<tr>
					<td colspan="7" align="center">没有查询记录</td>
				</tr>
				<%
				}
				%>
				<% 
					String metierName = "";
					for(int i = 0 ; i < queryList.size() ; i++){
						Map item = (Map)queryList.get(i);
						Integer type = (Integer)item.get("meiter");
						if(type == null){
							metierName = "所有";
						}else{
							if(1 == type){
								metierName = "教师";
							}else if(2 == type){
								metierName = "研究生";
							}else if(3 == type){
								metierName = "本科生";
							}else{
								metierName = "所有";
							}
						}
						
						String _deptcode = (String)item.get("deptcode");
						String _deptname = (String)item.get("deptname");
						String _userid = (String)item.get("userid");
						String _username = (String)item.get("username");
						String _host = (String)item.get("host");
						String _loginip = (String)item.get("loginip");
						String _logintime = (String)item.get("logintime");
						String _logouttime = (String)item.get("logouttime");
						
						if(_logintime != null){
							_logintime = _logintime.substring(0,_logintime.length() - 2);
						}
						
						if(_logouttime != null){
							_logouttime = _logouttime.substring(0,_logouttime.length() - 2);
						}
						
						
						if(_loginip != null && _loginip.indexOf(",") != -1){
							_loginip = _loginip.substring(0,_loginip.indexOf(","));
						}
				%>
					<tr>
						<td><%=_deptname %></td>
						<td align="center"><%=metierName %></td>
						<td><%=_username %></td>
						<td align="center"><%=_host %></td>
						<td><%=_loginip %></td>
						<td align="center"><%=_logintime %></td>
						<td align="center"><%=_logouttime %></td>
					</tr>
				<% 
					}
				%>
			</table>
		</div>
	</form>
<script type=text/javascript>
		Calendar.setup(
		{
			inputField  : "starttime",	// 接受输入值的控件
			button      : "_starttime",	// 调用日历的控件
			ifFormat    : "%Y-%m-%d"	// 日期格式
		}		
		);
		
		Calendar.setup(
		{
			inputField  : "endtime",	// 接受输入值的控件
			button      : "_endtime",	// 调用日历的控件
			ifFormat    : "%Y-%m-%d"	// 日期格式
		}		
		);
				
</script>
</body>
</html>